/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.comandos.admin;

import br.ufc.quixada.adrs.interfaces.Comando;
import br.ufc.quixada.adrs.model.Prazo;
import br.ufc.quixada.adrs.service.PrazoService;
import br.ufc.quixada.adrs.util.Msg;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Escritorio projetos
 */
public class CmdRemoverPrazo implements Comando {

    public String executa(HttpServletRequest request, HttpServletResponse response) {
        Long idPrazo = Long.parseLong(request.getParameter("prazo_id"));
        PrazoService ps = new PrazoService();
        Prazo p = new Prazo();
        p.setId(idPrazo);
        if (ps.deletePrazo(p)) {
            request.getSession().setAttribute("sucesso", Msg.SUCCESSFULLY_DELETED);
            List<Prazo> prazosAbertos = (List<Prazo>) request.getSession().getAttribute("prazosAbertos");
            for (int i = 0; i < prazosAbertos.size(); i++) {
                if (prazosAbertos.get(i).getId().compareTo(idPrazo) == 0) {
                    prazosAbertos.remove(i);
                }
            }
        } else {
            request.getSession().setAttribute("erro", Msg.OPERATIONAL_ERROR_DELETING_PRAZO);
        }
        return "/admin/admin_gerenciar_prazo.jsp";
    }
}
